<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <!-- <link rel="stylesheet" href="bootstrap-custom/dist/css/bootstrap.css"> -->
  <link rel="stylesheet" href="custom.css">
  <title>Bootstrap</title>
  <style>
    #result {
      display: none;
    }

    .title {
      margin-top: 100px;
      margin-bottom: 50px;
    }

    .operate button {
      margin: 0 auto;
    }
  </style>
</head>
<body>
  <h2 class="title col-sm-6 offset-sm-3 col-12">注册</h2>
  <form id="myForm" class="col-sm-6 offset-sm-3 col-12">
    <div class="form-group form-row">
      <label class="col-form-label col-2" for="name">姓名</label>
      <input class="form-control col-10" id="name" name="name" type="text"/>
    </div>
    <div class="form-group form-row">
      <label class="col-form-label col-2" for="password">密码</label>
      <input class="form-control col-10" id="password" name="password" type="password"/>
    </div>
    <div class="form-group form-row">
      <label class="col-form-label col-2" for="cellphone">电话</label>
      <input class="form-control col-10" id="cellphone" name="cellphone" type="text"/>
    </div>
    <div class="form-group form-row">
      <label class="col-form-label col-2" for="address">地址</label>
      <input class="form-control col-10" id="address" name="address" type="text"/>
    </div>
    <div id="result" class="alert alert-danger">

    </div>
    <div class="form-group form-row operate">
      <button class="btn btn-primary" type="submit">提交</button>
    </div>
  </form>
  <script>
    var form = document.querySelector('#myForm');
    var result = document.querySelector('#result');
    form.addEventListener('submit', function (e) {
      if (!document.querySelector('[name=password]').value) {
        result.style.display = 'block';
        result.innerHTML = '密码为空';
      } else {
        result.style.display = 'none';
      }
      e.preventDefault();
    });
  </script>
</body>
</html>
